package com.haiyou.dc.io;


import java.io.*;

public class TestIO {

    private static String fileName = "E:\\IdeaProjects\\my-java-project\\dc-guava\\src\\main\\java\\com\\haiyou\\dc\\io\\io.txt";

    public static void main(String[] args) throws IOException {

  

//        FileInputStream fileInputStream=null;
//        Reader reader = null;
//        InputStreamReader inputStreamReader = null;
//        FileReader fileReader = null;
//        BufferedReader bufferedReader = null;
//        try {
//            fileReader = new FileReader(fileName);
//            int ch;
//            while ((ch = fileReader.read()) != -1) {
//                System.out.print((char) ch);
//            }
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                if (fileReader != null) {
//                    fileReader.close();
//                }
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }

        test2();
//        System.out.println("\r\n--------------------------------->");
//        test1();
//        System.out.println("\r\n--------------------------------->");
//        test3();
    }

    private static void test1() throws IOException {

        try (FileReader fileReader = new FileReader(fileName)) {
            char[] buff = new char[1024];
            int count;
            while ((count = fileReader.read(buff)) != -1) {
                System.out.print(new String(buff, 0, count));
            }
        }
    }

    private static void test2() throws IOException {
        try (FileReader fileReader = new FileReader(fileName)) {
            int count;
            while ((count = fileReader.read()) != -1) {
                System.out.print((char) count);
            }
        }
    }

    private static void test3() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
        String data;
        while ((data = bufferedReader.readLine()) != null) {
            System.out.println(data);
        }
    }
}
